﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.IO;

namespace FrameWork.web.Includes.WebServices
{
    public partial class BaiduSiteMap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            base.Response.Cache.SetNoStore();
            base.Response.ContentType = "application/xml";
            DataTable table = new DataTable();
            MemoryStream w = new MemoryStream();
            XmlTextWriter writer = new XmlTextWriter(w, Encoding.UTF8);
            writer.Formatting = Formatting.Indented;
            writer.WriteStartDocument();
            writer.WriteStartElement("document");
            writer.WriteElementString("webSite", "站点域名");
            writer.WriteElementString("webMaster", "管理员邮箱");
            writer.WriteElementString("updatePeri", "15");
            foreach (DataRow row in table.Rows)
            {
                writer.WriteStartElement("item");
                writer.WriteElementString("title", row["title"].ToString());
    
                writer.WriteElementString("link", "文章的URL");
                writer.WriteElementString("description", row["shortcontent"].ToString());
                writer.WriteElementString("text", Regex.Replace(row["content"].ToString(), "<.+?>", "", RegexOptions.IgnoreCase));
    
                writer.WriteElementString("image", "图片的URL");
                writer.WriteElementString("headlineImg", string.Empty);
                string str3 = row["tagnamestr"].ToString();
                if (str3.StartsWith("|") && str3.EndsWith("|"))
                {
                    str3 = str3.Substring(0, str3.Length - 1);
                    str3 = str3.Substring(1, str3.Length - 1).Replace("|", " ");
                }
                writer.WriteElementString("keywords", str3);
                writer.WriteElementString("category", row["chname"].ToString());
                writer.WriteElementString("author", row["author"].ToString());
                writer.WriteElementString("source", row["source"].ToString());
                writer.WriteElementString("pubDate", row["addtime"].ToString());
                writer.WriteEndElement();
            }
            writer.WriteEndDocument();
            writer.Flush();
            byte[] bytes = w.ToArray();
            base.Response.Write(Encoding.UTF8.GetString(bytes));
            base.Response.End();
            writer.Close();
            w.Close();
            w.Dispose();
        }
    }
}
